<?php
namespace Test;

class ConvertCourse extends Convert
{
    public function convert($school, $schoolId, $groupinfo, $spaceid, $classId, $class)
    {
        printf("  Traverse old course data.\n");
        // 遍历旧数据
        // 先获取旧数据
        $schedules = $this->connection->table('yuanbao_v1.t_course')->where('classId', '=', $class->id)->get();

        ConvertSchool::$store['course'] = [];

        $record = [];

        // 课程表列表
        foreach ($schedules as $schedule) {
            printf("  Schedule id [%3d] Publish data - %s\n", $schedule->id, $schedule->publishTime);
            // 利用课程表id检索课程
            // 旧的数据是以天为划分单位
            $days = $this->connection->table('yuanbao_v1.t_course_day')->where('publishId', '=', $schedule->id)->lists('id');
            printf("    Course day ID list: %s\n", implode(",", $days));

            $courseTimeList = $this->connection->table('yuanbao_v1.t_course_info')->whereIn('courDateId', $days)->groupBy('courseTime')->lists('courseTime');

            foreach ($courseTimeList as $courseTime) {
                printf("    Course time: %s\n", $courseTime);
            }

//            foreach ($days as $day)
//            {
//                $courses = $this->connection->table('yuanbao_v1.t_course_info')->where('courDateId', '=', $day->Id)->get();
//
//                foreach ($courses as $course)
//                {
//                    printf("  course time: %s\n", $course->courseTime);
//
//                    if (isset(ConvertSchool::$store['course'][$course->course])) {
//
//                    }
//                }
//            }
        }
    }
}